home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 8
/
Eagles_Nest_Mac_Collection_Disc_8.TOAST
/
Developer Tools⁄Additions
/
Mandlebrot
/
Mandlebrot Folder
/
DrawMandel881.c
< prev
next >
Wrap
Text File
|
1990-05-07
|
6KB
|
240 lines
/* *********************************************************************************
FILE: DrawMandel881.c
DESCRIPTION: DrawMandel is the main loop. Picks a color using the value
calculated by calcMandel to index into the system CLUT.
Then uses the toolbox call RGBForeColor to set the line color
and finally a call to LineTo. This is the 68881 version of
DrawMandel. Uses in-line assembly code to perform the 'calcMandel'
function (return a value for the color lookup at each point
in the field).
AUTHOR: Bruce E. Gladstone
Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
Revision History:
============================================================
5/1/90 - Release to Compuserve
============================================================
COMMENTS:
None.
******************************************************************************** */
#include <stdio.h>
#include <MacTypes.h>
#include <WindowMgr.h>
#include <MenuMgr.h>
#include <EventMgr.h>
#include <ToolboxUtil.h>
#include <ControlMgr.h>
#include <color.h>
#include <colortoolbox.h>
#include "Mandelbrot.h"
/* ---------------------------- Global Variables ---------------------------------- */
extern int colorQD;
extern int quitFlag;
extern int linearFlag;
extern int custPict;
extern int numColorBits;
extern int numColors, brushSize;
extern int limit;
extern int n;
extern long startTime, now;
extern float res;
extern float centx, centy;
extern float xmin, xmax, ymin, ymax;
extern float delx, dely;
/* ---------------------------- Global MacTypes ----------------------------------- */
extern Str255 str;
extern CTabHandle myColorHandle;
extern RGBColor aColor;
extern Rect myRect, dragRect;
extern WindowPtr aboutWindow;
extern MenuHandle appleMenu, mandelMenu, editMenu, xMenu, yMenu, resMenu, timeMenu;
extern WindowPtr myWindow;
/* --------------------------- Local Prototypes --------------------------------- */
void drawMandel ( void );
int calcMandel ( float, float );
int eventCheck ( void );
void updateMenus ( void );
/* --------------------------------------------------------------------------------
drawMandel - 5/01/90 beg
-------------------------------------------------------------------------------- */
void
drawMandel()
{
int n;
long nx, ny;
long xres, yres;
float x, y, del;
Rect aRect;
int eventResult;
myRect = (*myWindow).portRect;
xres = myRect.right;
yres = myRect.bottom;
xmin = centx - res;
xmax = centx + res;
ymin = centy - res;
ymax = centy + res;
delx = ( xmax - xmin )/( xres+1 );
dely = ( ymax - ymin )/( yres+1 );
if ( delx > dely )
{
dely = delx;
}
else
{
delx = dely;
}
PenSize ( brushSize , brushSize );
del = delx*brushSize;
y = ymin;
ny = 0;
nx = 0;
while ( ny < ( yres - 1 ))
{
x = xmin;
nx = 0;
while ( nx < ( xres - 1 ))
{
asm {
;==========================================================
; The following is a 68881 assembly version of calcMandel
; The register assigments are:
; zreal FP1
; zimag FP2
; zr2 FP3
; zi2 FP4
; zreal1 FP5
; zreal2 FP6
; creal 8(A6)
; cimag 20(A6)
; count D7
;==========================================================
;
fmove.s (x),fp1 ; zreal
fmove.s (y),fp2 ; zimag
fmove.s #100.0,fp5 ; zreal1
fmove.s #200.0,fp6 ; zreal2
moveq #1,d7 ;
bra @lptest ;
loop: ;
fmove.x fp1,fp3 ; zr2 = zreal * zreal
fmul.x fp1,fp3 ;
fmove.x fp2,fp4 ; zi2 = zimag * zimag
fmul.x fp2,fp4 ;
fmove.x fp3,fp0 ; if (( zr2 + zi2 ) > 4.0 ) break
fadd.x fp4,fp0 ;
fcmp.s #4.0,fp0 ;
fbgt @exit ;
fmul.s #2.0,fp2 ; zimag = 2*zreal*zimag+cimag
fmul.x fp1,fp2 ;
fadd.s (y),fp2 ;
fmove.x fp3,fp1 ; zreal = zr2 - zi2 + creal;
fsub.x fp4,fp1 ;
fadd.s (x),fp1 ;
fcmp.x fp6,fp1 ; if ( zreal == zreal2 )
fbne @nobreak ;
clr.w d7 ; count = 0
bra @exit ;
nobreak: ;
fmove.x fp5,fp6 ; zreal2 = zreal1
fmove.x fp1,fp5 ; zreal1 = zreal
lptest: ;
addq.w #1,d7 ; count++
cmp.w (limit),d7 ;
ble @loop ; continue
exit: ;
move.w d7,*n ; put count in n
;
} /* end assembly version of calcMandel */
if ( colorQD && (numColorBits > 2 )) /* color version */
{
if ( linearFlag )
{
if (( n == 0 ) || ( n >= limit ))
{
n = numColors - 1;
}
else
{
n = n * numColors / limit;
}
}
else
{
if (( n == 0 ) || ( n >= limit ))
{
n = numColors - 1;
}
else
{
n = n % numColors;
}
}
aColor = (**myColorHandle).ctTable[n].rgb;
RGBForeColor ( &aColor );
LineTo ( nx, ny );
}
else /* black and white version */
{
if (( n == 0 ) || ( n >= 256 ))
{
PenPat( black );
}
else if ( n > 50 )
{
PenPat( dkGray );
}
else if ( n > 10 )
{
PenPat( gray );
}
else if ( n > 2 )
{
PenPat( ltGray );
}
else
{
PenPat( white );
}
LineTo ( nx, ny );
}
if ( eventCheck () || quitFlag == TRUE ) goto breakOut;
nx = nx + brushSize; /* end of nx loop */
x = x + del;
}
ny = ny + brushSize; /* end of ny loop */
y = y + del;
MoveTo ( 0, ny );
}
breakOut:
{
MoveTo ( 0,0 );
now = ( TickCount() - startTime )/60;
updateMenus(); /* Call update here so we can record time */
}
} /* drawMandel() */
/* =============================== EOF ==========================================
Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
================================================================================ */